import numpy as np
import csv

filenames = ['submit/resnet101_0.974.csv', 'submit/resnet152_0.973.csv', 'submit/senet154_0.98209856.csv']
predictions_arr = np.zeros((len(filenames),5339),np.float32)

with open(filenames[0],'r') as csvfile:
    reader = csv.reader(csvfile)
    column = [row[0] for row in reader]
#print(column[0],column[1])

for i in range(len(predictions_arr)):
    arr = np.genfromtxt(filenames[i],delimiter=',',skip_header=1)
    predictions_arr[i,:] = arr[:,1]
	
avr_prediction = np.mean(predictions_arr,axis=0)

txt_file = open('avg.csv','w')
txt_file.write('pic_id,pred\n')

for i in range(avr_prediction.shape[0]):
    txt_file.write("%s,%.8f\n" % (column[i+1],avr_prediction[i]))
